package testMetier;

import static org.junit.Assert.*;

import java.text.SimpleDateFormat;
import java.util.Date;

import metier.Candidature;
import metier.Departement;
import metier.Entreprise;
import metier.Etudiant;
import metier.Stage;

import org.junit.Test;

public class testCandidature {

	@Test
	public void testCreationCandidature() throws InterruptedException 
	{
		//instances de test
		Departement mDepartement = null;
		Entreprise mEntreprise = null;
		Stage mStage = null;
		Etudiant mEtudiant = null;
		
		try
		{
			mDepartement = new Departement(1, "MIM", "test", "test");
			mEntreprise = new Entreprise(1, "caca1", "caca2");
			mStage = new Stage(mEntreprise, mDepartement, "MAJ systeme sauvegarde", "blablabla", "DTC", new Date(), new Date());
			mEtudiant = new Etudiant(1, mDepartement, "Pou", "Tine", "pou1", "azerty");
		}
		catch(Exception mException)
		{
			fail();
		}
		
		/**
		 * Test du constructeur
		 */
		//Etudiant null interdit
		try 
		{
			new Candidature(null, mStage);
			fail();
		} 
		catch (Exception e) {}
		
		//Etudiant null interdit
		try 
		{
			new Candidature(mEtudiant, null);
			fail();
		} 
		catch (Exception e) {}

		//Tout est bon
		try 
		{
			new Candidature(mEtudiant, mStage);
		} 
		catch (Exception e) 
		{
			fail();
		}
	}

	@Test
	public void testGetSet() {

		try
		{
			//instances de test
			Departement mDepartement = null;
			Entreprise mEntreprise = null;
			Stage mStage = null;
			Etudiant mEtudiant = null;
			Candidature mCandidature = new Candidature();
			Date date;
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
			
			try
			{
				mDepartement = new Departement(1, "MIM", "test", "test");
				mEntreprise = new Entreprise(1, "caca1", "caca2");
				mStage = new Stage(mEntreprise, mDepartement, "MAJ systeme sauvegarde", "blablabla", "DTC", new Date(), new Date());
				mEtudiant = new Etudiant(1, mDepartement, "Pou", "Tine", "pou1", "azerty");
			}
			catch(Exception mException)
			{
				fail();
			}

			//Test get/set etudiant
			mCandidature.setEtudiant(mEtudiant);
			assertEquals(mEtudiant, mCandidature.getEtudiant());
			
			//Test get/set stage
			mCandidature.setStage(mStage);
			assertEquals(mStage, mCandidature.getStage());
			
			//Test get/set date validationDepartement
			date = null;
			date = simpleDateFormat.parse("22/06/2006");
			mCandidature.setValidationDepartement(date);
			assertEquals(date, mCandidature.getValidationDepartement());
			
			//Test get/set date validationEntreprise
			date = null;
			date = simpleDateFormat.parse("23/06/2006");
			mCandidature.setValidationEntreprise(date);
			assertEquals(date, mCandidature.getValidationEntreprise());
			
			//Test get/set date validationEtudiant
			date = null;
			date = simpleDateFormat.parse("24/06/2006");
			mCandidature.setValidationEtudiant(date);
			assertEquals(date, mCandidature.getValidationEtudiant());
		}
		catch(Exception mException)
		{
			fail();
		}
	}
}
